import Vue from 'vue'
import VueRouter from 'vue-router'
// 路由组件
import Home from "@/views/Home"
import Login from "@/views/Login"
import Register from "@/views/Register"
import Search from "@/views/Search"

Vue.use(VueRouter)

// 重写push与replace
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace
// push方法重写
VueRouter.prototype.push=function(location,resolve,reject){
  if (resolve && reject) {
    originPush.call(this,location,resolve,reject)
  }else{
    originPush.call(this,location,()=>{},()=>{})
  }
}
// replace方法重写
VueRouter.prototype.replace=function(location,resolve,reject){
  if (resolve && reject) {
    originReplace.call(this,location,resolve,reject)
  }else{
    originReplace.call(this,location,()=>{},()=>{})
  }
}

const routes = [
  {
    path: '/',
    redirect:Home 
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta:{showFooter:true}
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta:{showFooter:false}
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,
    meta:{showFooter:false}
  },
  {
    path: '/search/:keyword?',
    name: 'Search',
    component: Search,
    meta:{showFooter:true}
  },
 
]

const router = new VueRouter({
  routes
})

export default router
